<?php

namespace Budget\BudgetBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity(repositoryClass="Budget\BudgetBundle\Repository\CategoryRepository")
 * @ORM\Table(name="categories")
 */
class Category
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Assert\NotBlank()
     * @ORM\Column(type="string", length=50)
     */
    protected $name;

    /**
     * @ORM\ManyToOne(targetEntity="Family", inversedBy="categories")
     * @ORM\JoinColumn(name="family_id", referencedColumnName="id", nullable=true)
     */
    protected $family;
    
    /**
     * @ORM\Column(type="datetime")
     */
    protected $date_created;

    /**
     * @ORM\OneToMany(targetEntity="Category", mappedBy="parent")
     */
    protected $children;
    
    /**
     * @ORM\OneToMany(targetEntity="Expense", mappedBy="category")
     */
    protected $expenses;
    
    /**
     * @ORM\OneToMany(targetEntity="PlannedExpense", mappedBy="category")
     */
    protected $planned_expenses;
    

    /**
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="children")
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true)
     */
    protected $parent;
    
    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    protected $date_deleted;
    
     /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="deleted_by", referencedColumnName="id")
     */
    protected $deleted_by;
    
    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="created_by", referencedColumnName="id")
     */
    protected $created_by;
    /**
     *
     * @ORM\Column(type="boolean", nullable=true, name="is_saver", options={"default" = 0})
     */
    protected $isSaver;
    
    public function __construct()
    {
        $this->setDateCreated(new \DateTime());
        //$this->setDateDeleted(null);
    }
    
    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return Category
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set family
     *
     * @param integer $family
     * @return Category
     */
    public function setFamily($family)
    {
        $this->family = $family;

        return $this;
    }

    /**
     * Get family
     *
     * @return integer 
     */
    public function getFamily()
    {
        return $this->family;
    }

    /**
     * Set created
     *
     * @param \DateTime $created
     * @return Category
     */
    public function setCreated($created)
    {
        $this->created = $created;

        return $this;
    }

    /**
     * Get created
     *
     * @return \DateTime 
     */
    public function getCreated()
    {
        return $this->created;
    }


    /**
     * Set parent
     *
     * @param intiger $parent
     * @return Parent
     */
    public function setParent($parent)
    {
        $this->parent = $parent;

        return $this;
    }

    
    /**
     * Set children
     *
     * @param intiger children
     * @return children
     */
    public function setChildren($children)
    {
        $this->children = $children;

        return $this;
    }

    /**
     * Get children
     *
     * @return integer 
     */
    public function getChildren()
    {
        return $this->children;
    }
    
    
//    public function  getCategory() {
//        return $this;
//    }

    
    public function __toString()
    {
        return $this->getName();
    }

    /**
     * Add children
     *
     * @param \Budget\BudgetBundle\Entity\Category $children
     * @return Category
     */
    public function addChild(\Budget\BudgetBundle\Entity\Category $children)
    {
        $this->children[] = $children;

        return $this;
    }

    /**
     * Remove children
     *
     * @param \Budget\BudgetBundle\Entity\Category $children
     */
    public function removeChild(\Budget\BudgetBundle\Entity\Category $children)
    {
        $this->children->removeElement($children);
    }

    /**
     * Add expenses
     *
     * @param \Budget\BudgetBundle\Entity\Expense $expenses
     * @return Category
     */
    public function addExpense(\Budget\BudgetBundle\Entity\Expense $expenses)
    {
        $this->expenses[] = $expenses;

        return $this;
    }

    /**
     * Remove expenses
     *
     * @param \Budget\BudgetBundle\Entity\Expense $expenses
     */
    public function removeExpense(\Budget\BudgetBundle\Entity\Expense $expenses)
    {
        $this->expenses->removeElement($expenses);
    }

    /**
     * Get expenses
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getExpenses()
    {
        return $this->expenses;
    }

    /**
     * Set date_created
     *
     * @param \DateTime $dateCreated
     * @return Category
     */
    public function setDateCreated($dateCreated)
    {
        $this->date_created = $dateCreated;

        return $this;
    }

    /**
     * Get date_created
     *
     * @return \DateTime 
     */
    public function getDateCreated()
    {
        return $this->date_created;
    }

    /**
     * Set date_deleted
     *
     * @param \DateTime $dateDeleted
     * @return Category
     */
    public function setDateDeleted($dateDeleted)
    {
        $this->date_deleted = $dateDeleted;

        return $this;
    }

    /**
     * Get date_deleted
     *
     * @return \DateTime 
     */
    public function getDateDeleted()
    {
        return $this->date_deleted;
    }

    /**
     * Set deleted_by
     *
     * @param \Budget\BudgetBundle\Entity\User $deletedBy
     * @return Category
     */
    public function setDeletedBy(\Budget\BudgetBundle\Entity\User $deletedBy = null)
    {
        $this->deleted_by = $deletedBy;

        return $this;
    }

    /**
     * Get deleted_by
     *
     * @return \Budget\BudgetBundle\Entity\User 
     */
    public function getDeletedBy()
    {
        return $this->deleted_by;
    }

    /**
     * Set created_by
     *
     * @param \Budget\BudgetBundle\Entity\User $createdBy
     * @return Category
     */
    public function setCreatedBy(\Budget\BudgetBundle\Entity\User $createdBy = null)
    {
        $this->created_by = $createdBy;

        return $this;
    }

    /**
     * Get created_by
     *
     * @return \Budget\BudgetBundle\Entity\User 
     */
    public function getCreatedBy()
    {
        return $this->created_by;
    }

    /**
     * Get parent
     *
     * @return \Budget\BudgetBundle\Entity\Category 
     */
    public function getParent()
    {
        return $this->parent;
    }

    /**
     * Add planned_expenses
     *
     * @param \Budget\BudgetBundle\Entity\PlannedExpense $plannedExpenses
     * @return Category
     */
    public function addPlannedExpense(\Budget\BudgetBundle\Entity\PlannedExpense $plannedExpenses)
    {
        $this->planned_expenses[] = $plannedExpenses;

        return $this;
    }

    /**
     * Remove planned_expenses
     *
     * @param \Budget\BudgetBundle\Entity\PlannedExpense $plannedExpenses
     */
    public function removePlannedExpense(\Budget\BudgetBundle\Entity\PlannedExpense $plannedExpenses)
    {
        $this->planned_expenses->removeElement($plannedExpenses);
    }

    /**
     * Get planned_expenses
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getPlannedExpenses()
    {
        return $this->planned_expenses;
    }

    /**
     * Set isSaver
     *
     * @param boolean $isSaver
     * @return Category
     */
    public function setSaver($isSaver)
    {
        $this->isSaver = $isSaver;

        return $this;
    }

    /**
     * Get isSaver
     *
     * @return boolean 
     */
    public function isSaver()
    {
        return $this->isSaver;
    }
}
